package com.shut.vehicle.task;

import com.shut.vehicle.service.BookingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * @author 卢斌
 */
@EnableScheduling
@Component
public class CleanSnapshotTask {

    @Autowired
    private BookingRecordService bookingRecordService;

    @Scheduled(fixedRate = 60000)
    public void clean() {
        LocalDateTime localDateTime = LocalDateTime.now();
        localDateTime = localDateTime.plusHours(-48);
        ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
        Date date = Date.from(zdt.toInstant());
        bookingRecordService.cleanUnFinishedService(date);
    }


}
